<?php 
/**
 * 此文件需要引用外部的变量如下：
 * $zoneWidth 广告位宽度
 * $zoneHeight 广告位高度
 * $adRecord 广告数据行
 * $adInfo 广告类型详细信息
 *
 * 为防止变量名冲突，此文件内的变量都以下划线开头
 */

$_className = 'zn_text-' . time();
$_boxWidth  = $zoneWidth - 2;
$_boxHeight = $zoneHeight - 2;

$_vertMarginCount = $adInfo['row'];
$_horMarginCount  = $adInfo['col'];
$_vertMarginCount = $_vertMarginCount < 2 ? 2 : $_vertMarginCount;
$_horMarginCount  = $_horMarginCount  < 2 ? 2 : $_horMarginCount;

$_topMargin = round(($_boxHeight - ($adInfo['row'] * $adInfo['height'])) / $_vertMarginCount);
$_topMargin = $_topMargin < 5 ? 5 : $_topMargin;

$_leftMargin = round(($_boxWidth - ($adInfo['col'] * $adInfo['width'])) / $_horMarginCount);
$_leftMargin = $_leftMargin < 5 ? 5 : $_leftMargin;

echo <<<EOD
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>^_^</title>
<link href="http://t.ju33.com:89/t/zn/public.css" rel="stylesheet" type="text/css" />
<style type="text/css">
.{$_className} { position:relative; width:{$_boxWidth}px; height:{$_boxHeight}px; margin:auto; overflow:hidden; list-style:none;  }
.{$_className} li { position:absolute; text-align:center; width:{$adInfo['width']}px; height:{$adInfo['height']}px; }

EOD;

$_counter = 0;
$_top     = 0;
$_left    = 0;

for($i = 0; $i < $adInfo['row']; $i++) {
    $_left = $_leftMargin;

    for($i2 = 0; $i2 < $adInfo['col']; $i2++) {
        echo <<<EOD
#li{$_counter} { top:{$_top}px; left:{$_left}px; }

EOD;
        $_left = $_left + $adInfo['width'] + $_leftMargin;
        $_counter++;
    }

    $_top  = $_top + $_topMargin;
    $_top = $_top + $adInfo['height'];
}

echo <<<EOD
</style>
</head>
<body>
<ul class="{$_className}">

EOD;

foreach($adRecord as $k => $v) {
    $_liId = "li{$k}";

echo <<<EOD
    <li id="{$_liId}">{$v['code2']}</li>

EOD;
}

echo <<<EOD
</ul>
<script type="text/javascript">
var FAX560CPCCONF = {url : ''};
</script>
<script type="text/javascript" charset="utf-8" src="{$jsFile}"></script>
</body>
</html>
EOD;
